home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-10-21 | 4.9 KB | 206 lines | [TEXT/KAHL] |
- // This is based on the sample code on the QuickTime 1.5 CD ROM
- //
- // Display a movie in a window using a movie controller
- // The window is larger than the movie, if the user clicks
- // in the content area of the window, hide the controller
- // and stop the movie playing, which will show the badge.
- //
- // Copyright: © 1992-4 by Apple Computer, Inc., all rights reserved.
- //
-
- #include "mtb.h"
-
- void CreateMovieWindow( Movie aMovie ) ;
- void DestroyMovieWindow( WindowPtr aWindow ) ;
- void MainEventLoop( void ) ;
- void InitMac( void ) ;
-
-
- void CreateMovieWindow( Movie aMovie )
- {
- Rect aRect;
- MovieController aController;
- WindowPtr aWindow;
- RGBColor nattyGray = { 45000, 45000, 45000 } ;
-
- // prototype::
- GWorldPtr SetTransferProcsForMovie( Movie aMovie ) ;
-
- if( aMovie == nil )
- CheckError( paramErr, "\pCreateMovieWindow was passed nil for aMovie") ;
-
- // Use the movie bounding rect to size the movie
- GetMovieBox( aMovie, &aRect );
-
- // create a window for the movie
- aWindow = NewCWindow( nil,
- &aRect,
- "\pMovie",
- false,
- noGrowDocProc,
- (WindowPtr)-1,
- true,
- 0 );
-
- // set our port to the newly created movie window
- SetPort (aWindow);
-
- // set the movies environment to the current
- // port and gDevice (pass nil for defaults)
- SetMovieGWorld( aMovie, nil, nil ) ;
-
- // set up an offscreen bitmap and transfer proc for the movie
- // GWorldPtr SetTransferProcsForMovie( Movie aMovie ) ;
-
- SetTransferProcsForMovie( aMovie ) ;
-
- // create a movie controller for the movie
- aController = NewMovieController (aMovie, &aRect, mcTopLeftMovie);
-
- // should have some error handling here
- if (aController == nil)
- ExitToShell();
-
- // get the bounding rect of the movie plus the controller
- CheckError( MCGetControllerBoundsRect(aController, &aRect), "\pMCGetControllerBoundsRect") ;
-
- SizeWindow (aWindow, aRect.right,
- aRect.bottom - 1, true);
-
- // move it to {50,50} on the main device and show it
- MoveWindow ( aWindow, 50, 50, true );
- ShowWindow ( aWindow );
-
- // store a reference to the movie controller for this window
- // in the refcon field of this window, 1 movie per window...
- SetWRefCon ( aWindow, (long)aController );
-
- }
-
- void DestroyMovieWindow( WindowPtr aWindow )
- {
- Movie aMovie ;
- MovieController aController ;
-
- aController = (MovieController)GetWRefCon( aWindow ) ;
- if( aController != nil ) {
- aMovie = MCGetMovie( aController ) ;
- if( aMovie != nil ) {
- DisposeMovie (aMovie);
- }
- DisposeMovieController (aController);
- }
-
- DisposeWindow(aWindow);
- }
-
- void MainEventLoop( void )
- {
- Boolean done = false;
- OSErr err;
- EventRecord theEvent;
- WindowPtr whichWindow;
- short part;
- Boolean wasMovieEvent ;
- MovieController aController ;
-
- // use this in calls to MCDoAction
- long myMCActionParams ;
-
- while (!done) {
-
- WaitNextEvent(everyEvent, &theEvent, 0, nil );
-
- // get the movie associated with the pront window
- aController = (MovieController)( GetWRefCon(FrontWindow()) );
-
- // check we have a valid controller, and
- // if so, see if the controller can handle
- // this event
-
- if( aController != nil )
- wasMovieEvent = MCIsPlayerEvent(aController, &theEvent) ;
- else
- wasMovieEvent = false ;
-
- // if the controller didn't or couldn't handle it
- // we need to handle it in the main event loop.
-
- if (!wasMovieEvent) {
-
- switch (theEvent.what) {
-
- case updateEvt:
- whichWindow = (WindowPtr)theEvent.message;
- BeginUpdate (whichWindow);
- EraseRect (&whichWindow->portRect);
- EndUpdate (whichWindow);
- break;
-
- case mouseDown:
- part = FindWindow (theEvent.where,
- &whichWindow);
- // we only have one window, handle the event
- switch (part) {
- case inGoAway:
- done = TrackGoAway (whichWindow,
- theEvent.where);
-
- // if the window got closed, dispose of our movie
- // and the controller and the window.
-
- if( done )
- DestroyMovieWindow( whichWindow ) ;
-
- break;
-
- case inDrag:
- DragWindow (whichWindow,
- theEvent.where,
- &qd.screenBits.bounds);
- break;
-
- case inContent:
- break ;
- }
- }
- }
- }
- }
-
- void InitMac( void )
- {
- InitGraf (&qd.thePort);
- InitFonts ();
- InitWindows ();
- InitMenus ();
- TEInit ();
- InitDialogs ((long)nil);
-
- MaxApplZone() ;
- MoreMasters() ; MoreMasters() ; MoreMasters() ; MoreMasters() ;
- MoreMasters() ; MoreMasters() ; MoreMasters() ; MoreMasters() ;
- MoreMasters() ; MoreMasters() ; MoreMasters() ; MoreMasters() ;
-
- if (!IsQuickTimeInstalled()) {
- CheckError(-1,"\pPlease install QuickTime and try again.");
- }
-
- CheckError( EnterMovies (), "\pEnterMovies failed" );
- }
-
-
-
- void main (void)
- {
-
- Movie aMovie ;
-
- InitMac() ;
-
- if(aMovie = GetMovie ()) {
- CreateMovieWindow( aMovie );
- MainEventLoop() ;
- }
- }
-